package org.example.springmvc.service;


import org.example.springmvc.dox.User;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class UserService {
    private static final List<User> users=create();
    private static List<User> create(){
        User u=User.builder()
                .id("1")
                .name("ji")
                .account("331")
                .password("$2a$10$lLhi8V6BALRbEB.giRveQu3ag2yZtAWrivLehg8r11KuwubOR9EmS")
                .role(User.ADMIN)
                .build();
        User u1=User.builder()
                .id("2")
                .name("as")
                .account("123")
                .password("$2a$10$lLhi8V6BALRbEB.giRveQu3ag2yZtAWrivLehg8r11KuwubOR9EmS")
                .role(User.USER)
                .build();
        return List.of(u,u1);
    }
    public List<User> getUsers() {
        return users;
    }
    public User getUserByAccountAndPasswprd(String account,String password) {
        return users.stream().filter(user -> user.getAccount().equals(account)).filter(user -> user.getPassword().equals(password)).findFirst().orElse(null);
    }
    public User getUserByAccount(String account) {
        return users.stream().filter(user -> user.getAccount().equals(account)).findFirst().orElse(null);
    }
}
